	var contextPath = $("#contextPath").val();
	var orderID=$("#orderID").val();
	var dataDIV=$("#dataDIV");
	var shoppingcartTips = $('.shoppingcart__tips');
$(function() {
	dataInit();
});

function dataInit(){
	dataDIV.empty();
	var status='';
	
	$.ajax({
		url:contextPath+"/order/detaiList",
		type:"post",
		async:true,
		dataType:"json",
		data:{"params['orderid']":orderID},
		success : function(data, textStatus) {
			var state = data.result.state;
			html = '';
			if(state == 1){
				$.each(data.dateilMap,function(i,v){
					var stateDIV="";
					if(v.state=="00"){
						status="00";
						stateDIV="待付款";
					}else if(v.state=="01"){
						status="01";
						stateDIV="待发货";
					}else if(v.state=="02"){
						status="02";
						stateDIV="待收货";
					}else if(v.state=="03"){
						status="03";
						stateDIV="已完成";
					}
					html+='<div class="order_item_top"><div class="order_code f0"><span class="icon_order_code dib vm"></span><span class="order_code_txt dib vm">订单号：'+v.order_id+'<em class="n">></em></span></div><div class="order_status">'+stateDIV+'</div></div>';
					html+='<div class="order_schedule"><div class="track_list">'+
						'<div id="submitOrder" class="track_list_item"><p class="status">提交订单</p><div class="status_chart"><i class="dib vm"></i><span class="dib vm"></span></div><p class="time">'+v.createTime+'</p></div>'+
						'<div id="payment" class="track_list_item"><p class="status">付款</p><div class="status_chart"><i class="dib vm"></i><span class="dib vm"></span></div><p class="time">'+v.payTime+'</p></div>'+
						'<div id="delivery" class="track_list_item"><p class="status">收货</p><div class="status_chart"><i class="dib vm"></i><span class="dib vm"></span></div><p class="time">'+v.deliveryTime+'</p></div>'+
						'<div id="complete" class="track_list_item"><p class="status">已完成</p><div class="status_chart"><i class="dib vm"></i><span class="dib vm"></span></div><p class="time">'+v.closingTime+'</p></div></div>';
					if(status=="00"){
						html+='<div class="order_item_operating tr f0">'+
						//<a class="ui_btn"href="javascript:;">取消订单</a>
						'<a class="ui_btn ui_btn_primary"href="javascript:;">付款</a></div>';
					}else if(status=="01"){
						//html+='<div class="order_item_operating tr f0"><a class="ui_btn"href="javascript:;">取消订单</a></div>';
					}else if(status=="02"){
						html+='<div class="order_item_operating tr f0"><a class="ui_btn ui_btn_primary"href="javascript:;" onclick="confirmGoods('+v.order_id+');">确认收货</a></div>';
					}
						
					html+='</div><div class="order_address"><p class="receiver"><b>'+v.receiverName+'</b><span>'+v.receiverPhone+'</span></p><p><span class="dib vm icon_address"></span><span class="dib vm">'+v.receiverAddress+'</span></p></div><div><ul class="order_list"><li class="order_item">';
					$.each(v.goodsList,function(j,item){
						html+='<div class="order_goods_item"><div class="goods_img">';
						if(item.isPointsBuy == "01"){
							if(item.goodsThumb==null){
								html += '<i class="vip_mark"></i><a href="#"><img src="'+contextPath+'/static/images/icon_default_02.jpg" onclick="goodDateil('+item.goods_id+');">'
							}else{
								html+='<i class="vip_mark"></i><a href="#"><img src="'+item.goodsThumb+'" onerror="this.src=\''+contextPath+'/static/images/icon_default_02.jpg\'" onclick="goodDateil('+item.goods_id+');">';
							}
							if(item.usePrice == 0){
								html += '</a></div><div class="goods_info"><div class="order_goods_info"><p class="goods_info_name" goodsId = '+item.goods_id+' onclick="goodDateil('+item.goods_id+');"><a href="#">'+item.title+'</a></p><div class="goods_info_price tr"><p class="rebate"><em class="n">'+item.usePointsNum/item.number+'</em> 兑换券</p></div></div><div class="order_goods_info"><div class="goods_info_color">'+item.specDesc+'</div><div class="goods_info_quantity"> X'+item.number+' </div></div></div></div>'
							}else{
								html += '</a></div><div class="goods_info"><div class="order_goods_info"><p class="goods_info_name" goodsId = '+item.goods_id+' onclick="goodDateil('+item.goods_id+');"><a href="#">'+item.title+'</a></p><div class="goods_info_price tr"><p class="rebate"><em class="n">'+item.usePointsNum/item.number+'</em> 兑换券</p><p class="rebate"> + <span>'+item.usePrice/item.number+'</span>元</p></div></div><div class="order_goods_info"><div class="goods_info_color">'+item.specDesc+'</div><div class="goods_info_quantity"> X'+item.number+' </div></div></div></div>'
							}
						}else{
							if(item.goodsThumb==null){
								html += '<a href="#"><img src="'+contextPath+'/static/images/icon_default_02.jpg" onclick="goodDateil('+item.goods_id+');">'
							}else{
								html+='<a href="#"><img src="'+item.goodsThumb+'" onerror="this.src=\''+contextPath+'/static/images/icon_default_02.jpg\'" onclick="goodDateil('+item.goods_id+');">';
							}
							html += '</a></div><div class="goods_info"><div class="order_goods_info"><p class="goods_info_name" goodsId = '+item.goods_id+' onclick="goodDateil('+item.goods_id+');"><a href="#">'+item.title+'</a></p><div class="goods_info_price tr"><p class="normal">&yen;'+item.currentPrice+'</p></div></div><div class="order_goods_info"><div class="goods_info_color">'+item.specDesc+'</div><div class="goods_info_quantity"> X'+item.number+' </div></div></div></div>'
						}
					});
					html+='</li></ul></div><div class="goods_total"><p class="fix"><span class="l">商品总额：</span><span class="r">&yen;'+v.totalPrice+'</span></p><p class="fix"><span class="l">兑换券：</span><span class="r">'+v.usePoints+'</span></p><p class="fix"><span class="l">运费：</span><span class="r">&yen;'+v.transitPrice+'</span></p><p class="fix"><span class="r">实付款：<em class="n c_bright">&yen;'+v.realPrice+'</em></span></p></div>';
				});
				dataDIV.append(html);
				if(status=="00"){
					$("#submitOrder").addClass(" track_list_item_active");
				}else if(status=="01"){
					$("#submitOrder").addClass(" track_list_item_active");
					$("#payment").addClass(" track_list_item_active");
				}else if(status=="02"){
					$("#submitOrder").addClass(" track_list_item_active");
					$("#payment").addClass(" track_list_item_active");
					$("#delivery").addClass(" track_list_item_active");
				}else if(status=="03"){
					$("#submitOrder").addClass(" track_list_item_active");
					$("#payment").addClass(" track_list_item_active");
					$("#delivery").addClass(" track_list_item_active");
					$("#complete").addClass(" track_list_item_active");
				}
				
				dataDIV.show();
			}
				goodsIsNull();
		},
		error : function(XMLHttpRequest, textStatus, errorThrown){
			layer.open({
			    content:textStatus,
			    time: 2
			});
		}
	});	
}

function goodDateil(goodID){
	window.location.href=contextPath+"/goods/detailPage?goodsId="+goodID;
}

function confirmGoods(id){
	$.ajax({
		url:contextPath+"/order/confirmGoods",
		type:"post",
		async:true,
		dataType:"json",
		data:{"params['orderID']":id},
		success : function(data, textStatus) {
			var state = data.result.state;
			if(state == 1){
				layer.open({
				    title: '提示',
				    content:data.result.message,
				    btn: ['我知道了']
				});
				dataInit();
			}
		},error : function(XMLHttpRequest, textStatus, errorThrown){
			isTab=true;
			$(".lodingStyle").hide();
			layer.open({
			    title: '提示',
			    content: '确认失败，请重试',
			    btn: ['我知道了']
			});	
		}
	});
}

function goodsIsNull(){
	if($(".order_code").length==0){
		shoppingcartTips.css('display','flex');
	}else{
		shoppingcartTips.hide();
	}
}